//Wu Xianqun
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.JTextField;
import javax.swing.JTable;
import java.awt.AWTException;
import java.awt.Font;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JTabbedPane;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import com.melloware.jintellitype.HotkeyListener;   
import com.melloware.jintellitype.JIntellitype;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;





public class PriSecGui extends Thread implements HotkeyListener {
	private JFrame frame;
	private JFrame aboutUs;
	private JTextField textField;
	private JLabel currentTime;
	private JLabel lblNewLabel_1;
	private JCheckBoxMenuItem remind;
	private JTabbedPane tabbedPane;
	private TrayIcon.MessageType messageType;	
	private TrayIcon trayIcon;
	private SystemTray systemTray;
	private PopupMenu pop = new PopupMenu();
	private MenuItem exit = new MenuItem("Exit");
	private MenuItem show = new MenuItem("Show");
	private JTable table_1;
	private JTable table_2;
	private JTable table_3;
	private File textFile;
	private Image icon;
	private Vector<Task> tasks=null;
	private Vector<Task> tasks2=null;
	private Vector<Task> tasks3=null;
	String userInputAtToDo="";
	String userInputAtDone="";
	String userInputAtOverDue="";
	String taskDoneIndex;
	String taskRemoveIndexToDo="";
	String taskRemoveIndexDone="";
	String taskRemoveIndexOverDue="";
	String editedTask="";
	Object[][] showList=new Object[1000][6];
	boolean visible=true;
	static final int KEY_1 = 88;
	static int m;
	static int n;
	static int o=0;
	static int w0,w1,w2,w3,w4;
	static int sym1=0;
	static int sym2=0;
	static int sym3=0;
	static int timeInteval=10;
	static int themeIndex=7;
	static int isReminderEnable=1;
	int freq=1800;
	Long remindTime=(long)43200;
	static Logger logger = Logger.getLogger(PriSecGui.class.getName());
	
	private void log4jInitial(){
		BasicConfigurator.configure();
	}

	/**
	 * Launch the application.
	 */

	/**
	 * Create the application.
	 */
	public PriSecGui() {
			// to set the default look and feel.
			try {
				JFrame.setDefaultLookAndFeelDecorated(true);
				UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
			} catch (Exception e) {
			e.printStackTrace();
			}
			initialize();
			//to create a system tray icon. 
			icon = Toolkit.getDefaultToolkit().getImage(
					this.getClass().getResource("sec.png"));

			if (SystemTray.isSupported()) {
				systemTray = SystemTray.getSystemTray();
				trayIcon = new TrayIcon(icon, "PriSec", pop);
				pop.add(show);
				pop.add(exit);

				try {
					systemTray.add(trayIcon);
				} catch (AWTException e1) {
					logger.error("failed to creat tray icon");
				}
				frame.addWindowListener(new WindowAdapter() {
					public void windowIconified(WindowEvent e) {
			        	logger.info("software closing");
						frame.setVisible(true);
					}
				});

				trayIcon.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent e) {
						if (e.getClickCount() == 1
								&& e.getButton() != MouseEvent.BUTTON3) {
							frame.setVisible(true);
							frame.setExtendedState(JFrame.NORMAL);
						}
					}
				});

				show.addActionListener(new ActionListener() {

							public void actionPerformed(ActionEvent e) {
								frame.setVisible(true);
								frame.setExtendedState(JFrame.NORMAL);
							}
						});
				exit.addActionListener(new ActionListener() {

							public void actionPerformed(ActionEvent e) {
								System.exit(0);
							}
						});
			}
			frame.setIconImage(icon);
	}
	/**
	 * Initialize the contents of the frame.
	 */
	@SuppressWarnings({ "serial"})
	private void initialize() {
		
		log4jInitial();
		logger.info("PriSecGui is ready.");
		readFromFile();
		frame = new JFrame("PriSec V0.2");
		frame.getContentPane().setFont(new Font("Berlin Sans FB Demi", Font.PLAIN, 12));
		frame.setBounds(100, 100, 661, 424);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		frame.setLocationRelativeTo(null);
		initHotkey();
		taskDoneIndex = "";
		taskRemoveIndexToDo = "";
		taskRemoveIndexDone = "";
		taskRemoveIndexOverDue="";
		
		 //save theme and reminder settings before closing
		 frame.addWindowListener(new WindowAdapter() {
			   public void windowClosing(WindowEvent e) {
				if(remind.isSelected())
					isReminderEnable=1;
				else
					isReminderEnable=0;
				long temp =(long) isReminderEnable;
				
			    writeToFile(themeIndex,temp);
			   } 
			  });

		
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(20, 106, 616, 235);
		frame.getContentPane().add(tabbedPane);
		
		//to create 3 tab for "Todo", "Done", "OverDue"
		JScrollPane scrollPane = new JScrollPane();
		tabbedPane.addTab("   To do    ", null, scrollPane, null);
		JScrollPane scrollPane1 = new JScrollPane();
		tabbedPane.addTab("    Done    ", null, scrollPane1, null);
		JScrollPane scrollPane2 = new JScrollPane();
		tabbedPane.addTab("  Overdue  ", null, scrollPane2, null);
		tabbedPane.addChangeListener(new ChangeListener(){
			public void stateChanged(ChangeEvent e){
				JTabbedPane pane=(JTabbedPane) e.getSource();
				if(pane!=tabbedPane)
					return;
			}
		});
        try   { 
            tabbedPane.setSelectedIndex(0); 
        } 
        catch   (Exception   e1)   { 
            System.out.println("cannot select Todo tab");
        } 

		//to create table for each tab
		DefaultTableModel model=new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
					"No.", "action", "Time", "Date"
			}
		);
		
		table_1=new JTable(model);
		
		table_1.getTableHeader().setReorderingAllowed(false);
		scrollPane.setViewportView(table_1);
		
		table_2=new JTable(model){
			public boolean isCellEditable(int row,int column){
				return false;
			}
		};
		table_2.getTableHeader().setReorderingAllowed(false);


		scrollPane1.setViewportView(table_2);
		
		table_3=new JTable(model){
			public boolean isCellEditable(int row,int column){
				return false;
			}
		};
		table_3.getTableHeader().setReorderingAllowed(false);


		scrollPane2.setViewportView(table_3);
		
		//to implement shortcut key
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	logger.info("key Ctrl+T pressed");
                tabbedPane.setSelectedIndex(0);
            }
        }, KeyEvent.VK_CONTROL,KeyEvent.VK_T);

		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	logger.info("key Ctrl+D pressed");
                tabbedPane.setSelectedIndex(1);
            }
        }, KeyEvent.VK_CONTROL,KeyEvent.VK_D);
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	logger.info("key Ctrl+O pressed");
                tabbedPane.setSelectedIndex(2);
            }
        }, KeyEvent.VK_CONTROL,KeyEvent.VK_O);
		
		//shortcut for undo
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	logger.info("key Ctrl+Z pressed");
                userInputAtToDo="undo";
            }
        }, KeyEvent.VK_CONTROL,KeyEvent.VK_Z);
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	logger.info("key Ctrl+Y pressed");
                userInputAtToDo="redo";
            }
        }, KeyEvent.VK_CONTROL,KeyEvent.VK_Y);
		
		//shortcut for changing theme
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	logger.info("key ALT+C pressed");
                changeTheme();
            }
        }, KeyEvent.VK_ALT,KeyEvent.VK_C);
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	textField.requestFocus();
            }
        }, KeyEvent.VK_ALT,KeyEvent.VK_A);
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            @SuppressWarnings("deprecation")
			public void handle() {
            	aboutUs = new JFrame("Format");
				aboutUs.getContentPane().setFont(new Font("Verdana", Font.BOLD, 20));
				aboutUs.setBounds(250, 220, 480, 300);
				aboutUs.getContentPane().setLayout(null);
				aboutUs.setLocationRelativeTo(null);
				JLabel about1 = new JLabel("1. Add: add \"action\" /\"deadline\"");
				about1.setFont(new Font("Verdana", Font.BOLD, 12));
				about1.setBounds(10, 20, 300, 11);
				aboutUs.getContentPane().add(about1);
				JLabel about2 = new JLabel("2. Delete: delete \"taskNo.\"");
				about2.setBounds(10, 50, 380, 11);
				about2.setFont(new Font("Verdana", Font.BOLD, 12));
				aboutUs.getContentPane().add(about2);
				JLabel about3 = new JLabel("3. Edit: edit \"taskNo.\" -a \"action\" -t \"time\" -d \"date\"");
				about3.setFont(new Font("Verdana", Font.BOLD, 12));
				about3.setBounds(10, 80, 380, 14);
				aboutUs.getContentPane().add(about3);
				JLabel about4 = new JLabel("4. Mark as done: mark \"taskNo.\"");
				about4.setFont(new Font("Verdana", Font.BOLD, 12));
				about4.setBounds(10, 113, 300, 11);
				aboutUs.getContentPane().add(about4);
				JLabel about5 = new JLabel("5. Set reminder frequence: freq -h \"hour\" -m \"minute\" -s \"second\"");
				about5.setFont(new Font("Verdana", Font.BOLD, 12));
				about5.setBounds(10, 140, 450, 20);
				aboutUs.getContentPane().add(about5);
				JLabel about6 = new JLabel("6. Set reminder time: time -h \"hour\" -m \"minute\" -s \"second\"");
				about6.setFont(new Font("Verdana", Font.BOLD, 12));
				about6.setBounds(10, 170, 450, 20);
				aboutUs.getContentPane().add(about6);
				JLabel about7 = new JLabel("7. Search: search \"keywords\"");
				about7.setFont(new Font("Verdana", Font.BOLD, 12));
				about7.setBounds(10, 200, 450, 20);
				aboutUs.getContentPane().add(about7);
				aboutUs.setResizable(false);
				JLabel about8 = new JLabel("8. Select: \"taskNo.\"");
				about8.setFont(new Font("Verdana", Font.BOLD, 12));
				about8.setBounds(10, 230, 450, 20);
				aboutUs.getContentPane().add(about8);
				aboutUs.setResizable(false);
				aboutUs.show();
				aboutUs.addKeyListener(new KeyAdapter() {
					@Override
					public void keyPressed(KeyEvent e) {
						aboutUs.dispose();
					}
				});
            }
        }, KeyEvent.VK_ALT,KeyEvent.VK_F);
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            @SuppressWarnings("deprecation")
			public void handle() {
            	aboutUs = new JFrame("Short cut keys");
				aboutUs.getContentPane().setFont(new Font("Verdana", Font.BOLD, 20));
				aboutUs.setBounds(250, 160, 350, 440);
				aboutUs.getContentPane().setLayout(null);
				aboutUs.setLocationRelativeTo(null);
				JLabel about1 = new JLabel("        1.show Todo list:          	     	  Ctrl+T");
				about1.setFont(new Font("Verdana", Font.BOLD, 12));
				about1.setBounds(10, 20, 300, 11);
				aboutUs.getContentPane().add(about1);
				JLabel about2 = new JLabel("        2.show Done list:         	    	    Ctrl+D");
				about2.setBounds(10, 50, 350, 11);
				about2.setFont(new Font("Verdana", Font.BOLD, 12));
				aboutUs.getContentPane().add(about2);
				JLabel about3 = new JLabel("        3.show Overdue list:       		    Ctrl+O");
				about3.setFont(new Font("Verdana", Font.BOLD, 12));
				about3.setBounds(10, 80, 300, 14);
				aboutUs.getContentPane().add(about3);
				JLabel about4 = new JLabel("        4.delete:                      	 	        Delete");
				about4.setFont(new Font("Verdana", Font.BOLD, 12));
				about4.setBounds(10, 110, 300, 11);
				aboutUs.getContentPane().add(about4);
				JLabel about5 = new JLabel("        5.mark as done:            	 	      Ctrl+M");
				about5.setFont(new Font("Verdana", Font.BOLD, 12));
				about5.setBounds(10, 140, 300, 11);
				aboutUs.getContentPane().add(about5);
				JLabel about6 = new JLabel("        6.change theme:             		     ALT+C");
				about6.setFont(new Font("Verdana", Font.BOLD, 12));
				about6.setBounds(10, 170, 300, 11);
				aboutUs.getContentPane().add(about6);
				JLabel about7 = new JLabel("        7.undo:                      	   	        Ctrl+Z");
				about7.setBounds(10, 200, 300, 11);
				about7.setFont(new Font("Verdana", Font.BOLD, 12));
				aboutUs.getContentPane().add(about7);
				JLabel about11 = new JLabel("        8.redo:                        	  	        Ctrl+Y");
				about11.setBounds(10, 230, 300, 11);
				about11.setFont(new Font("Verdana", Font.BOLD, 12));
				aboutUs.getContentPane().add(about11);
				JLabel about8 = new JLabel("        9.hide and show:               	 	  ALT+P");
				about8.setFont(new Font("Verdana", Font.BOLD, 12));
				about8.setBounds(10, 260, 300, 11);
				aboutUs.getContentPane().add(about8);
				aboutUs.setResizable(false);
				JLabel about12 = new JLabel("       10.focus on command bar:		   ALT+A");
				about12.setFont(new Font("Verdana", Font.BOLD, 12));
				about12.setBounds(10, 290, 300, 11);
				aboutUs.getContentPane().add(about12);
				aboutUs.setResizable(false);
				JLabel about13 = new JLabel("       11.focus on Todo table:      		  ALT+T");
				about13.setFont(new Font("Verdana", Font.BOLD, 12));
				about13.setBounds(10, 320, 300, 11);
				aboutUs.getContentPane().add(about13);
				aboutUs.setResizable(false);
				JLabel about14 = new JLabel("       12.command format help:    		ALT+F");
				about14.setFont(new Font("Verdana", Font.BOLD, 12));
				about14.setBounds(10, 350, 300, 11);
				aboutUs.getContentPane().add(about14);
				aboutUs.setResizable(false);
				JLabel about15 = new JLabel("       13.short cut key list:           		  ALT+S");
				about15.setFont(new Font("Verdana", Font.BOLD, 12));
				about15.setBounds(10, 380, 300, 15);
				aboutUs.getContentPane().add(about15);
				aboutUs.setResizable(false);
				aboutUs.show();
				aboutUs.addKeyListener(new KeyAdapter() {
					@Override
					public void keyPressed(KeyEvent e) {
						aboutUs.dispose();
					}
				});
            }
        }, KeyEvent.VK_ALT,KeyEvent.VK_S);
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	table_1.requestFocus();
            }
        }, KeyEvent.VK_ALT,KeyEvent.VK_T);
		
		//shortcut for marking a task as done
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	logger.info("key Ctrl+M pressed");
            	int[] doneIndexs=table_1.getSelectedRows();
				String temp="";
				if(doneIndexs!=null){
					if(tasks!=null)
						for(int i=0;i<doneIndexs.length;i++)
					 if(doneIndexs[i]<tasks.size()){
						 temp=temp+" "+tasks.get(doneIndexs[i]).getIDInteger();
					 }
					taskDoneIndex=temp;
				}
            }
        }, KeyEvent.VK_CONTROL,KeyEvent.VK_M);
		
		//shortcut for deleting a task
		ShortcutManager.getInstance().addShortcutListener(new ShortcutManager.ShortcutListener() {
            public void handle() {
            	logger.info("key DELETE pressed");
            	String temp;
            	int a = tabbedPane.getSelectedIndex();
            	
            	//to get the taskID.
				switch(a){
				case 0:
				{
					int[] removeIndexs=table_1.getSelectedRows();
					temp="";
					if(tasks!=null)
					for(int i=0;i<removeIndexs.length;i++)
					 if(removeIndexs[i]<tasks.size()){
						 temp=temp+" "+tasks.get(removeIndexs[i]).getIDInteger();
					 }
					taskRemoveIndexToDo=temp;
					break;
				}
				case 1:
				{
					int[] removeIndexs=table_2.getSelectedRows();
					temp="";
					if(tasks2!=null)
					for(int i=0;i<removeIndexs.length;i++)
					 if(removeIndexs[i]<tasks2.size()){
						 temp=temp+" "+tasks2.get(removeIndexs[i]).getIDInteger();
					}
					taskRemoveIndexDone=temp;
					break;
				}	
				case 2:
				{
					int[] removeIndexs=table_3.getSelectedRows();
					temp="";
					if(tasks3!=null)
					for(int i=0;i<removeIndexs.length;i++)
					 if(removeIndexs[i]<tasks3.size()){
						 temp=temp+" "+tasks3.get(removeIndexs[i]).getID();
					}
					taskRemoveIndexOverDue=temp;
					break;
				}
				default: assert false:"tab index is invalid";
				}
            }
        }, KeyEvent.VK_DELETE);


		
		//create a label for showing feedback
		currentTime = new JLabel();
		this.start();
		currentTime.setBounds(485, 361, 137, 15);
		frame.getContentPane().add(currentTime);
		
		
		//create the command bar
		textField = new JTextField();
		textField.setBounds(20, 60, 615, 34);
		textField.setFont(new Font("Dialog", Font.BOLD, 13));
		textField.addKeyListener(new KeyAdapter() {
			@SuppressWarnings("static-access")
			@Override
			public void keyPressed(KeyEvent e) {
				
				//search after entering every word
				if(e.getKeyCode()==e.VK_SPACE){
					int a = tabbedPane.getSelectedIndex();
					String input = textField.getText();
					if(input.length()>7)
					if(input.substring(0,6).compareTo("search")==0)
					{
						if(a==0)
							userInputAtToDo=textField.getText();
						if(a==1)
							userInputAtDone=textField.getText();
						if(a==2)
							userInputAtOverDue=textField.getText();
					}
					
				}
				
				//if input length less than 3, check it whether it is a task No. If it is, highlight it.
				if(e.getKeyCode()==e.VK_ENTER){
					int m = tabbedPane.getSelectedIndex();
					if(m==0){
					if(textField.getText().length()==1){
						if(tasks!=null)
						if(textField.getText().charAt(0)>'0'&&textField.getText().charAt(0)<=tasks.size()+48){
							table_1.setRowSelectionInterval(textField.getText().charAt(0)-49, textField.getText().charAt(0)-49);
							Rectangle rect = table_1.getCellRect(textField.getText().charAt(0)-49, 0, true);
							table_1.scrollRectToVisible(rect); 
						}
						textField.setText("");	
					}
					else
						if(textField.getText().length()==2){
						if(textField.getText().charAt(0)>'0'&&textField.getText().charAt(0)<='9'&&textField.getText().charAt(1)>='0'&&textField.getText().charAt(1)<='9')
						{
							int kkk =(textField.getText().charAt(0)-48)*10+textField.getText().charAt(1)-48;
							if(kkk<=tasks.size()){
								table_1.setRowSelectionInterval(kkk-1,kkk-1);
								Rectangle rect = table_1.getCellRect(kkk-1, 0, true);
								table_1.scrollRectToVisible(rect); 
							}
						}					
						textField.setText("");
					   }
						else{
								userInputAtToDo=textField.getText();
								textField.setText("");
							}
						}
					if(m==1)
					{
						if(textField.getText().length()==1){
							if(tasks2!=null)
							if(textField.getText().charAt(0)>'0'&&textField.getText().charAt(0)<=tasks2.size()+48){
								table_2.setRowSelectionInterval(textField.getText().charAt(0)-49, textField.getText().charAt(0)-49);
								Rectangle rect2 = table_2.getCellRect(textField.getText().charAt(0)-49, 0, true);
								table_2.scrollRectToVisible(rect2); ;
							}
							textField.setText("");	
						}
						else
							if(textField.getText().length()==2){
							if(textField.getText().charAt(0)>'0'&&textField.getText().charAt(0)<='9'&&textField.getText().charAt(1)>='0'&&textField.getText().charAt(1)<='9')
							{
								int kkk =(textField.getText().charAt(0)-48)*10+textField.getText().charAt(1)-48;
								if(kkk<=tasks2.size()){
									table_2.setRowSelectionInterval(kkk-1,kkk-1);
									Rectangle rect2 = table_2.getCellRect(kkk-1, 0, true);
									table_2.scrollRectToVisible(rect2); 
								}
							}					
							textField.setText("");
						   }
							else{
									userInputAtDone=textField.getText();
									textField.setText("");
								}
					}
					if(m==2){
						if(textField.getText().length()==1){
							if(tasks3!=null)
							if(textField.getText().charAt(0)>'0'&&textField.getText().charAt(0)<=tasks3.size()+48){
								table_3.setRowSelectionInterval(textField.getText().charAt(0)-49, textField.getText().charAt(0)-49);
								Rectangle rect2 = table_3.getCellRect(textField.getText().charAt(0)-49, 0, true);
								table_3.scrollRectToVisible(rect2); ;
							}
							textField.setText("");	
						}
						else
							if(textField.getText().length()==2){
							if(textField.getText().charAt(0)>'0'&&textField.getText().charAt(0)<='9'&&textField.getText().charAt(1)>='0'&&textField.getText().charAt(1)<='9')
							{
								int kkk =(textField.getText().charAt(0)-48)*10+textField.getText().charAt(1)-48;
								if(kkk<=tasks3.size()){
									table_3.setRowSelectionInterval(kkk-1,kkk-1);
									Rectangle rect2 = table_3.getCellRect(kkk-1, 0, true);
									table_3.scrollRectToVisible(rect2); 
								}
							}					
							textField.setText("");
						   }
							else{
									userInputAtOverDue=textField.getText();
									textField.setText("");
							}
					}
				}
			}
			});
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		JButton btnNewButton = new JButton("Mark as done");
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				int[] doneIndexs=table_1.getSelectedRows();
				String temp="";
				if(doneIndexs!=null){
					if(tasks!=null)
						for(int i=0;i<doneIndexs.length;i++)
					 if(doneIndexs[i]<tasks.size()){
						 temp=temp+" "+tasks.get(doneIndexs[i]).getIDInteger();
					 }
					taskDoneIndex=temp;
				}
			}
		});
		btnNewButton.setBounds(20, 356, 112, 25);
		frame.getContentPane().add(btnNewButton);
		
		JLabel lblCurrentTime = new JLabel("current time:");
		lblCurrentTime.setBounds(400, 361, 85, 15);
		frame.getContentPane().add(lblCurrentTime);
		
		JButton btnRemove = new JButton("Delete");
		btnRemove.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				
				//get the taskID
				int a = tabbedPane.getSelectedIndex();
				String temp;
				switch(a){
				case 0:
				{
					int[] removeIndexs=table_1.getSelectedRows();
					temp="";
					if(tasks!=null)
					for(int i=0;i<removeIndexs.length;i++)
					 if(removeIndexs[i]<tasks.size()){
						 temp=temp+" "+tasks.get(removeIndexs[i]).getIDInteger();
					 }
					taskRemoveIndexToDo=temp;
					break;
				}
				case 1:
				{
					int[] removeIndexs=table_2.getSelectedRows();
					temp="";
					if(tasks2!=null)
					for(int i=0;i<removeIndexs.length;i++)
					 if(removeIndexs[i]<tasks2.size()){
						 temp=temp+" "+tasks2.get(removeIndexs[i]).getIDInteger(); 
					}
					taskRemoveIndexDone=temp;
					break;
				}
				case 2:
				{
					int[] removeIndexs=table_3.getSelectedRows();
					temp="";
					if(tasks3!=null)
					for(int i=0;i<removeIndexs.length;i++)
					 if(removeIndexs[i]<tasks3.size()){
						 temp=temp+" "+tasks3.get(removeIndexs[i]).getIDInteger(); 
					}
					taskRemoveIndexOverDue=temp;
					break;
				}
				default: assert false: "tab index is invalid";
				}
			}
		});
		btnRemove.setBounds(142, 356, 112, 25);
		frame.getContentPane().add(btnRemove);
		
		//add menu bar
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBounds(0, 0, 655, 21);
		frame.getContentPane().add(menuBar);
		JMenu menuSetting = new JMenu("Setting");
		menuBar.add(menuSetting);
		JMenu menu = new JMenu("Reminder");
		menuSetting.add(menu);
		remind = new JCheckBoxMenuItem("Enable");
		readFromFile();
		if(isReminderEnable==0)
			remind.setSelected(false);
		else
			remind.setSelected(true);
		menu.add(remind);
	
		JMenu mnChangeTheme = new JMenu("Theme");
		menuSetting.add(mnChangeTheme);
			
		JMenuItem menuItem_1 = new JMenuItem("acryl");
		menuItem_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				changeTheme2();
			}
		});
		mnChangeTheme.add(menuItem_1);
		
		JMenuItem mntmNewMenuItem = new JMenuItem("aero");
		mntmNewMenuItem.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				changeTheme3();
			}
		});
		
		JMenuItem menuItem_5 = new JMenuItem("bernstein");
		mnChangeTheme.add(menuItem_5);
		menuItem_5.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				changeTheme4();
			}
		});
		
		JMenuItem mntmMint = new JMenuItem("mint");
		mntmMint.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				changeTheme1();
			}
		});
		mnChangeTheme.add(mntmMint);
		JMenuItem menuItem_6 = new JMenuItem("aluminium");
		mnChangeTheme.add(menuItem_6);
		menuItem_6.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				changeTheme5();
			}
		});
		JMenuItem menuItem_8 = new JMenuItem("graphite");
		mnChangeTheme.add(menuItem_8);
		menuItem_8.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				changeTheme6();
			}
		});
		JMenuItem menuItem_7 = new JMenuItem("hifi");
		mnChangeTheme.add(menuItem_7);
		menuItem_7.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				changeTheme7();
			}
		});
		JMenuItem menuItem_4 = new JMenuItem("luna");
		mnChangeTheme.add(menuItem_4);
		menuItem_4.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				changeTheme8();
			}
		});
		JMenuItem menuItem_3 = new JMenuItem("mcwin");
		mnChangeTheme.add(menuItem_3);
		mnChangeTheme.add(mntmNewMenuItem);
		
		JMenu mnNewMenu_1 = new JMenu("Help");
		menuBar.add(mnNewMenu_1);
		
		JMenuItem mntmNewMenuItem_1 = new JMenuItem("Command Format");
		mnNewMenu_1.add(mntmNewMenuItem_1);
		mntmNewMenuItem_1.addMouseListener(new MouseAdapter() {
			@SuppressWarnings("deprecation")
			@Override
			public void mousePressed(MouseEvent arg0) {
				JFrame aboutUs = new JFrame("Format");
				
				aboutUs.getContentPane().setFont(new Font("Verdana", Font.BOLD, 20));
				aboutUs.setBounds(250, 220, 480, 300);
				aboutUs.getContentPane().setLayout(null);
				aboutUs.setLocationRelativeTo(null);
				JLabel about1 = new JLabel("1. Add: add \"action\" /\"deadline\"");
				about1.setFont(new Font("Verdana", Font.BOLD, 12));
				about1.setBounds(10, 20, 300, 11);
				aboutUs.getContentPane().add(about1);
				JLabel about2 = new JLabel("2. Delete: delete \"taskNo.\"");
				about2.setBounds(10, 50, 380, 11);
				about2.setFont(new Font("Verdana", Font.BOLD, 12));
				aboutUs.getContentPane().add(about2);
				JLabel about3 = new JLabel("3. Edit: edit \"taskNo.\" -a \"action\" -t \"time\" -d \"date\"");
				about3.setFont(new Font("Verdana", Font.BOLD, 12));
				about3.setBounds(10, 80, 380, 14);
				aboutUs.getContentPane().add(about3);
				JLabel about4 = new JLabel("4. Mark as done: mark \"taskNo.\"");
				about4.setFont(new Font("Verdana", Font.BOLD, 12));
				about4.setBounds(10, 113, 300, 11);
				aboutUs.getContentPane().add(about4);
				JLabel about5 = new JLabel("5. Set reminder frequence: freq -h \"hour\" -m \"minute\" -s \"second\"");
				about5.setFont(new Font("Verdana", Font.BOLD, 12));
				about5.setBounds(10, 140, 450, 20);
				aboutUs.getContentPane().add(about5);
				JLabel about6 = new JLabel("6. Set reminder time: time -h \"hour\" -m \"minute\" -s \"second\"");
				about6.setFont(new Font("Verdana", Font.BOLD, 12));
				about6.setBounds(10, 170, 450, 20);
				aboutUs.getContentPane().add(about6);
				JLabel about7 = new JLabel("7. Search: search \"keywords\"");
				about7.setFont(new Font("Verdana", Font.BOLD, 12));
				about7.setBounds(10, 200, 450, 20);
				aboutUs.getContentPane().add(about7);
				aboutUs.setResizable(false);
				JLabel about8 = new JLabel("8. Select: \"taskNo.\"");
				about8.setFont(new Font("Verdana", Font.BOLD, 12));
				about8.setBounds(10, 230, 450, 20);
				aboutUs.getContentPane().add(about8);
				aboutUs.setResizable(false);
				aboutUs.show();
			}
		});
		JMenuItem mntmNewMenuItem_3 = new JMenuItem("Short Cut Keys");
		mnNewMenu_1.add(mntmNewMenuItem_3);
		mntmNewMenuItem_3.addMouseListener(new MouseAdapter() {
			@SuppressWarnings("deprecation")
			@Override
			public void mousePressed(MouseEvent arg0) {
				aboutUs = new JFrame("Short cut keys");
				aboutUs.getContentPane().setFont(new Font("Verdana", Font.BOLD, 20));
				aboutUs.setBounds(250, 160, 350, 440);
				aboutUs.getContentPane().setLayout(null);
				aboutUs.setLocationRelativeTo(null);
				JLabel about1 = new JLabel("        1.show Todo list:          	     	  Ctrl+T");
				about1.setFont(new Font("Verdana", Font.BOLD, 12));
				about1.setBounds(10, 20, 300, 11);
				aboutUs.getContentPane().add(about1);
				JLabel about2 = new JLabel("        2.show Done list:         	    	    Ctrl+D");
				about2.setBounds(10, 50, 350, 11);
				about2.setFont(new Font("Verdana", Font.BOLD, 12));
				aboutUs.getContentPane().add(about2);
				JLabel about3 = new JLabel("        3.show Overdue list:       		    Ctrl+O");
				about3.setFont(new Font("Verdana", Font.BOLD, 12));
				about3.setBounds(10, 80, 300, 14);
				aboutUs.getContentPane().add(about3);
				JLabel about4 = new JLabel("        4.delete:                      	 	        Delete");
				about4.setFont(new Font("Verdana", Font.BOLD, 12));
				about4.setBounds(10, 110, 300, 11);
				aboutUs.getContentPane().add(about4);
				JLabel about5 = new JLabel("        5.mark as done:            	 	      Ctrl+M");
				about5.setFont(new Font("Verdana", Font.BOLD, 12));
				about5.setBounds(10, 140, 300, 11);
				aboutUs.getContentPane().add(about5);
				JLabel about6 = new JLabel("        6.change theme:             		     ALT+C");
				about6.setFont(new Font("Verdana", Font.BOLD, 12));
				about6.setBounds(10, 170, 300, 11);
				aboutUs.getContentPane().add(about6);
				JLabel about7 = new JLabel("        7.undo:                      	   	        Ctrl+Z");
				about7.setBounds(10, 200, 300, 11);
				about7.setFont(new Font("Verdana", Font.BOLD, 12));
				aboutUs.getContentPane().add(about7);
				JLabel about11 = new JLabel("        8.redo:                        	  	        Ctrl+Y");
				about11.setBounds(10, 230, 300, 11);
				about11.setFont(new Font("Verdana", Font.BOLD, 12));
				aboutUs.getContentPane().add(about11);
				JLabel about8 = new JLabel("        9.hide and show:               	 	  ALT+P");
				about8.setFont(new Font("Verdana", Font.BOLD, 12));
				about8.setBounds(10, 260, 300, 11);
				aboutUs.getContentPane().add(about8);
				aboutUs.setResizable(false);
				JLabel about12 = new JLabel("       10.focus on command bar:		   ALT+A");
				about12.setFont(new Font("Verdana", Font.BOLD, 12));
				about12.setBounds(10, 290, 300, 11);
				aboutUs.getContentPane().add(about12);
				aboutUs.setResizable(false);
				JLabel about13 = new JLabel("       11.focus on Todo table:      		  ALT+T");
				about13.setFont(new Font("Verdana", Font.BOLD, 12));
				about13.setBounds(10, 320, 300, 11);
				aboutUs.getContentPane().add(about13);
				aboutUs.setResizable(false);
				JLabel about14 = new JLabel("       12.command format help:    		ALT+F");
				about14.setFont(new Font("Verdana", Font.BOLD, 12));
				about14.setBounds(10, 350, 300, 11);
				aboutUs.getContentPane().add(about14);
				aboutUs.setResizable(false);
				JLabel about15 = new JLabel("       13.short cut key list:           		  ALT+S");
				about15.setFont(new Font("Verdana", Font.BOLD, 12));
				about15.setBounds(10, 380, 300, 15);
				aboutUs.getContentPane().add(about15);
				aboutUs.setResizable(false);
				aboutUs.show();
				aboutUs.addKeyListener(new KeyAdapter() {
					@Override
					public void keyPressed(KeyEvent e) {
						aboutUs.dispose();
					}
				});
			}
		});
		JMenuItem mntmNewMenuItem_2 = new JMenuItem("About PriSec");
		mntmNewMenuItem_2.addMouseListener(new MouseAdapter() {
			@SuppressWarnings("deprecation")
			@Override
			public void mousePressed(MouseEvent arg0) {
				JFrame aboutUs = new JFrame("About PriSec");
				
				aboutUs.getContentPane().setFont(new Font("Berlin Sans FB Demi", Font.PLAIN, 12));
				aboutUs.setBounds(250, 220, 320, 180);
				aboutUs.setResizable(false);
				aboutUs.getContentPane().setLayout(null);
				aboutUs.setLocationRelativeTo(null);
				JLabel about1 = new JLabel("PriSec");
				about1.setBounds(180, 20, 300, 10);
				aboutUs.getContentPane().add(about1);
				JLabel about2 = new JLabel("Version: 0.2");
				about2.setBounds(180, 45, 300, 10);
				aboutUs.getContentPane().add(about2);
				JLabel about3 = new JLabel("All rights reserved.");
				about3.setBounds(180, 65, 300, 15);
				aboutUs.getContentPane().add(about3);
				JLabel about4 = new JLabel("");
				about4.setBounds(180, 85, 300, 10);
				aboutUs.getContentPane().add(about4);
				JLabel about5 = new JLabel("          PriSec Team");
				about5.setBounds(180, 105, 300, 10);
				aboutUs.getContentPane().add(about5);
				JLabel about6 = new JLabel();
				about6.setIcon(new ImageIcon(this.getClass().getResource("sec1.png")));
				about6.setBounds(30, 0, 160, 160);
				aboutUs.getContentPane().add(about6);
				aboutUs.show();
			}
		});
		mnNewMenu_1.add(mntmNewMenuItem_2);
		
		
		
		lblNewLabel_1 = new JLabel("What can I do for you?");
		lblNewLabel_1.setBounds(20, 31, 500, 19);
		frame.getContentPane().add(lblNewLabel_1);
		lblNewLabel_1.setFont(new Font("Dialog", Font.BOLD, 13));
		menuItem_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				changeTheme9();
			}
		});
		switch(themeIndex){
		case 1:changeTheme1();break;
		case 2:changeTheme2();break;
		case 3:changeTheme3();break;
		case 4:changeTheme4();break;
		case 5:changeTheme5();break;
		case 6:changeTheme6();break;
		case 7:changeTheme7();break;
		case 8:changeTheme8();break;
		case 9:changeTheme9();break;	
		default: assert false:"theme index is invalid";
		}
		frame.setResizable(false);
		frame.setVisible(true);
		
	}

	public String getUserInput(){
		while(userInputAtToDo.length()==0&&userInputAtDone.length()==0&&userInputAtOverDue.length()==0&&taskRemoveIndexOverDue==""&&taskDoneIndex==""&&taskRemoveIndexToDo==""&&taskRemoveIndexDone==""&&editedTask==""){
			try {
				sleep(1);
			} catch (InterruptedException e) {
				System.out.println("Last command is interrupted.");
			}
			return null;
		}
		String temp1=userInputAtToDo;
		String temp2=userInputAtDone;
		String temp7=userInputAtOverDue;
		String temp3=taskDoneIndex;
		String temp4=taskRemoveIndexToDo;
		String temp5=taskRemoveIndexDone;
		String temp8=taskRemoveIndexOverDue;
		String temp6=editedTask;
		userInputAtToDo="";
		userInputAtDone="";
		userInputAtOverDue="";
		taskDoneIndex="";
		taskRemoveIndexToDo="";
		taskRemoveIndexDone="";
		taskRemoveIndexOverDue="";
		editedTask="";
		if(temp1!="")
			return("0"+temp1);
		if(temp2!="")
			return("1"+temp2);
		if(temp3!="")
			return("2"+temp3);
		if(temp4!="")
			return("3"+temp4);
		if(temp5!="")
			return("4"+temp5);
		if(temp6!="")
			return("5"+temp6);
		if(temp7!="")
			return("6"+temp7);
		else
			return("7"+temp8);
	}
	
	
	@SuppressWarnings("serial")
	public void showTaskAtToDo(Vector<Task> Tasks){
		Object[][] showList3=new Object[Tasks.size()][4];
		Object[][] temp=new Object[Tasks.size()][5];
		tasks=Tasks;
		for(int i=0;i<Tasks.size();i++){
			temp[i]=Tasks.get(i).toArray();
			showList3[i][0]=i+1;
			showList3[i][1]=temp[i][1];
			showList3[i][2]=temp[i][2];
			showList3[i][3]=temp[i][3];
		}
		table_1.setModel(new DefaultTableModel(
				showList3,new String[]{"No.", "Action", "Time", "Date"}){
			public boolean isCellEditable(int row, int column){
				if(column==0)
					return false;
				return true;
			}
		});
		table_1.getTableHeader().setResizingAllowed(false);
		table_1.getColumnModel().getColumn(0).setPreferredWidth(1);
		table_1.getColumnModel().getColumn(1).setPreferredWidth(410);
		table_1.getColumnModel().getColumn(2).setPreferredWidth(45);
		table_1.getColumnModel().getColumn(3).setPreferredWidth(60);
		
		//to detect editing and store edited task information
		table_1.getModel().addTableModelListener(new TableModelListener(){
			public void tableChanged(TableModelEvent e){
				String a =table_1.getValueAt(e.getLastRow(),3).toString();
				if(a.length()>0){
					if(a.charAt(0) == ' ')
					a=a.substring(1);
				}
				editedTask = tasks.get(e.getLastRow()).getID()+";"+table_1.getValueAt(e.getLastRow(),1).toString()+";"+table_1.getValueAt(e.getLastRow(),2).toString()+";"+a;
		}
		});
	}
	public void showTaskAtDone(Vector<Task> tasks){
		Object[][] showList2=new Object[tasks.size()][4];
		Object[][] temp=new Object[tasks.size()][5];
		this.tasks2=tasks;
		for(int i=0;i<tasks2.size();i++){
			temp[i]=tasks.get(i).toArray();
			showList2[i][0]=i+1;
			showList2[i][1]=temp[i][1];
			showList2[i][2]=temp[i][2];
			showList2[i][3]=temp[i][3];
		}
		table_2.setModel(new DefaultTableModel(
				showList2,
				new String[] {
					"No.","Action", "Time", "Date"
				}));
		table_2.getTableHeader().setResizingAllowed(false);
		table_2.getColumnModel().getColumn(0).setPreferredWidth(1);
		table_2.getColumnModel().getColumn(1).setPreferredWidth(410);
		table_2.getColumnModel().getColumn(2).setPreferredWidth(45);
		table_2.getColumnModel().getColumn(3).setPreferredWidth(60);
	}
	public void showTaskAtOverdue(Vector<Task> tasks){
		Object[][] showList3=new Object[tasks.size()][4];
		Object[][] temp=new Object[tasks.size()][5];
		this.tasks3=tasks;
		for(int i=0;i<tasks3.size();i++){
			temp[i]=tasks.get(i).toArray();
			showList3[i][0]=i+1;
			showList3[i][1]=temp[i][1];
			showList3[i][2]=temp[i][2];
			showList3[i][3]=temp[i][3];
		}
		table_3.setModel(new DefaultTableModel(
				showList3,
				new String[] {
					"No.","Action", "Time", "Date"
				}));
		table_3.getTableHeader().setResizingAllowed(false);
		table_3.getColumnModel().getColumn(0).setPreferredWidth(1);
		table_3.getColumnModel().getColumn(1).setPreferredWidth(410);
		table_3.getColumnModel().getColumn(2).setPreferredWidth(45);
		table_3.getColumnModel().getColumn(3).setPreferredWidth(60);
	}
	public void showResponse(String string) {
		lblNewLabel_1.setText(string);
	}

	public void onHotKey(int key) {
		
		//global hotkey
	      switch (key) {   
	       case KEY_1:   
	          {
	        	  logger.info("key ALT+P pressed");
	        	  if(frame.isVisible()){
	        		  frame.setVisible(false);
	        	  }
	        	  else{
	        		  	frame.setVisible(true);
	        		  	frame.setExtendedState(JFrame.NORMAL);
	        	  }
	        	  break;
	          }
	       }   
	  
	}
	public void destroy() {   
	       JIntellitype.getInstance().unregisterHotKey(KEY_1);    
	      System.exit(0);   
	   }   
	    void initHotkey() {   
	      JIntellitype.getInstance().registerHotKey(KEY_1, JIntellitype.MOD_ALT,   
	               (int) 'P');   
	        JIntellitype.getInstance().addHotKeyListener(this);   
	    }
	    
	    //change theme
	private void changeTheme1(){
		try {
			com.jtattoo.plaf.mint.MintLookAndFeel.setTheme("Default");
			UIManager.setLookAndFeel("com.jtattoo.plaf.mint.MintLookAndFeel");
			this.frame.getRootPane().updateUI();
			SwingUtilities.updateComponentTreeUI(frame);
			themeIndex=1;
		}catch (Exception e) {
			System.out.println("failed to change theme to mint");
		}
	}private void changeTheme2(){
		try {
			com.jtattoo.plaf.acryl.AcrylLookAndFeel.setTheme("Default");
			UIManager.setLookAndFeel("com.jtattoo.plaf.acryl.AcrylLookAndFeel");
			this.frame.getRootPane().updateUI();
			SwingUtilities.updateComponentTreeUI(frame);
			themeIndex=2;
		}catch (Exception e) {
			System.out.println("failed to change theme to acryl");
		}
	}
	private void changeTheme3(){
		try {
			com.jtattoo.plaf.aero.AeroLookAndFeel.setTheme("Default");
			UIManager.setLookAndFeel("com.jtattoo.plaf.aero.AeroLookAndFeel");
			this.frame.getRootPane().updateUI();
			SwingUtilities.updateComponentTreeUI(frame);
			themeIndex=3;
		}catch (Exception e) {
			System.out.println("failed to change theme to aero");
		}
	}
	private void changeTheme4(){
		try {
			com.jtattoo.plaf.bernstein.BernsteinLookAndFeel.setTheme("Default");
			UIManager.setLookAndFeel("com.jtattoo.plaf.bernstein.BernsteinLookAndFeel");
			this.frame.getRootPane().updateUI();
			SwingUtilities.updateComponentTreeUI(frame);
			themeIndex=4;
		}catch (Exception e) {
			System.out.println("failed to change theme to bernstein");
		}
	}
	private void changeTheme5(){
		try {
			com.jtattoo.plaf.aluminium.AluminiumLookAndFeel.setTheme("Default");
			UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel");
			this.frame.getRootPane().updateUI();
			SwingUtilities.updateComponentTreeUI(frame);
			themeIndex=5;
		}catch (Exception e) {
			System.out.println("failed to change theme to aluminium");
		}
	}
	private void changeTheme6(){
		try {
			com.jtattoo.plaf.graphite.GraphiteLookAndFeel.setTheme("Default");
			UIManager.setLookAndFeel("com.jtattoo.plaf.graphite.GraphiteLookAndFeel");
			this.frame.getRootPane().updateUI();
			SwingUtilities.updateComponentTreeUI(frame);
			themeIndex=6;
		}catch (Exception e) {
			System.out.println("failed to change theme to graphite");
		}
	}
	private void changeTheme7(){
		try {
			com.jtattoo.plaf.hifi.HiFiLookAndFeel.setTheme("Default");
			UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
			this.frame.getRootPane().updateUI();
			SwingUtilities.updateComponentTreeUI(frame);
			themeIndex=7;
		}catch (Exception e) {
			System.out.println("failed to change theme to hifi");
		}
	}
	private void changeTheme8(){
		try {
			com.jtattoo.plaf.luna.LunaLookAndFeel.setTheme("Default");
			UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel");
			this.frame.getRootPane().updateUI();
			SwingUtilities.updateComponentTreeUI(frame);
			themeIndex=8;
		}catch (Exception e) {
			System.out.println("failed to change theme to luna");
		}
	}
	private void changeTheme9(){
		try {
			com.jtattoo.plaf.mcwin.McWinLookAndFeel.setTheme("Default");
			UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
			SwingUtilities.updateComponentTreeUI(frame);
			themeIndex=9;
		}catch (Exception e) {
			System.out.println("failed to change theme to mcwin");
		}
	}
	
	//for shortcut CTRL+C
	private void changeTheme(){
		switch(o){
		case 0:changeTheme1();o++;break;
		case 1:changeTheme2();o++;break;
		case 2:changeTheme3();o++;break;
		case 3:changeTheme4();o++;break;
		case 4:changeTheme5();o++;break;
		case 5:changeTheme6();o++;break;
		case 6:changeTheme7();o++;break;
		case 7:changeTheme8();o++;break;
		case 8:changeTheme9();o=0;break;
		default: assert false:"theme index is valid";
		}
	}
	@SuppressWarnings("static-access")
	void showReminding(String string){
		trayIcon.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				frame.setVisible(true);
			}});
		trayIcon.displayMessage("PriSec Reminder", string,messageType.NONE);
	}
	public String getID(int taskNo){
		int id = tabbedPane.getSelectedIndex();
		switch(id){
			case 0:
				if(tasks.size()>=taskNo&&taskNo>=1)
					return tasks.get(taskNo-1).getID();
				break;
			case 1:
				if(tasks2.size()>=taskNo&&taskNo>=1)
					return tasks2.get(taskNo-1).getID();
				break;
			case 2:
				if(tasks3.size()>=taskNo&&taskNo>=1)
					return tasks3.get(taskNo-1).getID();
				break;
		}
		return null;
	}
	
	//get the current system time and show it on the label.
	public   void   run() 
	{ 
	try   { 
	        while(true){ 
	        	SimpleDateFormat   sdf   =   new   SimpleDateFormat( " yyyy-MM-dd  HH:mm:ss "); 
	        		currentTime.setText(sdf.format(new   Date())); 
	        		sleep(1000); 
	        	} 
	       }catch   (Exception   ex)   { 
	    	   ex.printStackTrace(); 
	       } 
	}
	public boolean isReminderEnable(){
		return remind.isSelected();
	}
	public void writeToFile(int a, Long b) {
			textFile = new File("setting.txt");
		
		try {
			BufferedWriter writer = new BufferedWriter(new FileWriter(textFile));
			writer.write(a+"");
			writer.write(b+"");
			writer.newLine();
			writer.write(freq+"");
			writer.newLine();
			writer.write(remindTime+"");

			writer.newLine();
			writer.close();
			return;
		}catch (IOException e) {
			System.out.println(e);
		}
	}
	public void writeToFile2(int a, Long b) {
		textFile = new File("setting.txt");
	
	try {
		BufferedWriter writer = new BufferedWriter(new FileWriter(textFile));
		writer.write(themeIndex+""+isReminderEnable);
		writer.newLine();
		writer.write(a+"");
		writer.newLine();
		writer.write(b+"");
		writer.newLine();
		writer.close();
		return;
	}catch (IOException e) {
		System.out.println(e);
	}
}
	
	public boolean readFromFile() {
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader("setting.txt"));
		} catch (FileNotFoundException e) {
			//System.out.println(e);
			themeIndex = 7;
			isReminderEnable = 1;
			return false;
		}
			String s=null;
			try {
				s = reader.readLine();
			} catch (IOException e) {
				System.out.println("read from file failed");
			}
			int a = Integer.valueOf(s).intValue();
			themeIndex=a/10;
			isReminderEnable=a-a/10*10;
			return true;
	}
	public boolean readFromFile2() {
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader("setting.txt"));
		} catch (FileNotFoundException e) {
			//System.out.println(e);
			themeIndex = 7;
			isReminderEnable = 1;
			freq = 1800;
			remindTime = (long) 43200;
			return false;
		}
			String s=null;
			try {
				s = reader.readLine();
			} catch (IOException e) {
				System.out.println("read from file failed");
			}
			int a = Integer.valueOf(s).intValue();
			themeIndex=a/10;
			isReminderEnable=a-a/10*10;
			try {
				s = reader.readLine();
			} catch (IOException e) {
				System.out.println("read from file failed");
			}
			a=Long.valueOf(s).intValue();
			freq = Integer.valueOf(s).intValue();
			try {
				s = reader.readLine();
			} catch (IOException e) {
				System.out.println("read from file failed");
			}
			remindTime = (long) Long.valueOf(s).intValue();
			return true;
	}
	public Long getReminderTime(){
		readFromFile2();
		return remindTime; 
	}
	public int getReminderFreq(){
		readFromFile2();
		return freq;
	}
	public void storeRemindSetting(int freq, Long time){
		this.freq=freq;
		this.remindTime=time;
		writeToFile2(freq,time);
	}
}